﻿#pragma once
#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <windows.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>

#define POS_X 24
#define POS_Y 5
#define WALL L'¤'
#define BODY L'¤'
#define FOOD L'¤'

#define KEY_PRESS(vk) ((GetAsyncKeyState(vk)&1)?1:0)

//类型声明
enum DIRECTION
{
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};

//蛇的状态
//正常状态，撞墙，撞自己...
enum GAME_STATUS
{
	OK,
	KILL_BY_WALL,
	KILL_BY_SELF,
	END_NORMAL
};
//蛇身的结点类型
typedef struct SnakeNode
{
	//坐标
	int x;
	int y;
	//指向下一节点的指针
	struct SnakeNode* next;
}SnakeNode,* pSnakeNode;

//贪吃蛇
typedef struct Snake
{
	pSnakeNode _pSnake;
	pSnakeNode _pFood;
	enum DIRECTION _dir;
	enum GAME_STATUS _status;
	int _food_weight;
	int _score;
	int _sleep_time;//控制速度

}Snake,* pSnake;

//函数声明

//游戏的初始化
void GameStart(pSnake ps);

//欢迎界面的打印
void WelcomeToGame();

//地图创建
void CreateMap();

//创建蛇
void InitSnake(pSnake ps);

//创建食物
void CreateFood(pSnake ps);

//运行游戏
void GameRun(pSnake ps);

void SnakeMove(pSnake ps);

_Bool NextIsFood(pSnakeNode pn, pSnake ps);

void EatFood(pSnakeNode pn,pSnake ps);

void NoFood(pSnakeNode pn, pSnake ps);

void KillByWall(pSnake ps);
void KillBySelf(pSnake ps);

void GameEnd(pSnake ps);